<div class="list-body">
	 <form id="business-search-form">
	 	<div class="row">
			<div class="search-input">
        		<input type="text"  id="business-name-input" placeholder="输入业务名称" onblur="Trim(this,this.value)">
        		<input type="text" name="name" id="businessNameDisNone" style="display: none;">
        		{{#if roleinfo.role}}
        			<input type="text"  id="business-uname-input" placeholder="输入所属用户" onblur="Trim(this,this.value)">
        			<input type="text" name="uname" id="businessUnameDisNone" style="display: none;">
				{{/if}}
        		<div style="display: none;">
					<input type="text" name="pageCurrent" value="1">
        			<input type="text" name="pageSize" value="12">
        		</div>
        		<button type="button" onclick="business_search_btn()" class="search-btn " data-icon="search"></button>
    		</div>
    		<a class="add-btn business-btn disable" onclick="dialog_business_addPage()"><i class="fa fa-plus-square-o"></i><span>添加业务</span></a>
		</div>
		<ul class="row business-list-content list-content">
	
		</ul>
	</form>
	<div id="pagination_business" style="text-align: center;display: none;"></div>
</div>

<script type="text/javascript">
	$(function(){
		 var bussinessTotalNum ;
		pagination_callback(1, 12,1);
		if('{{roleinfo.role}}'){
			$('.business-btn').addClass('disable');
			$('.business-btn').removeAttr('onclick');
		}else{
	      $('.business-btn').removeClass('disable');
	      $('.business-btn').attr('onclick');
	    }
	    $("input").placeholder();
	})
	function business_search_btn(){
		 $('#business-name-input').val()!='输入业务名称' ? $('#businessNameDisNone').val($('#business-name-input').val()) : $('#businessNameDisNone').val('');
	      if('{{roleinfo.role}}'){
	        $('#business-uname-input').val()!='输入所属用户' ? $('#businessUnameDisNone').val($('#business-uname-input').val()) : $('#businessUnameDisNone').val('');
	      }
		BJUI.ajax('ajaxform', {
		    url: '/business/list',
		    form: $.CurrentNavtab.find('#business-search-form'),
		    validate: false,
		    loadingmask: true,
		    okCallback: function(json, options) {
		    	$('#pagination_business').pagination('destroy')
		    	$('#pagination_business').pagination({
			   	 	total:json.totalRow, pageSize:12, callback:pagination_callback
				})
		    	bussinessTotalNum=json.totalRow;
		    	set_list(json);
			    if(json.totalRow<=12){
	                $("#pagination_business").css("display","none");
	              }else{
	                $("#pagination_business").css("display","block");
	            }
            
		    }
		})
	}

	function pagination_callback(pageCurrent, pageSize,num) {
		var	businessName,businessUname;
		businessName=$("#businessNameDisNone").val();
		if('{{roleinfo.role}}'){
			businessUname=$("#businessUnameDisNone").val();
		}
	    BJUI.ajax('doajax', {
	        url: '/business/list',
	        loadingmask: true,
	        data: {pageCurrent:pageCurrent, pageSize:pageSize,name:businessName,uname:businessUname},
	        okCallback: function(json, options) {
	        	if(json!=''){
	        		set_list(json);
	        	}
	        	if(num==1){
	            	 $('#pagination_business').pagination({
			   	 		total:json.totalRow, pageSize:12, callback:pagination_callback
					}) 
	            }
               bussinessTotalNum=json.totalRow;
                if(json.totalRow>pageSize){
	            	$("#pagination_business").css("display","block");
	            }else{
                    $("#pagination_business").css("display","none");
                }
	            
	        }
	    })
	}
	function set_list(json){
		$('.business-list-content').empty();
		var btnArr=[
				{title:"编辑",icon:"fa fa-edit",fun:"business_editPage"},
				{title:"详情",icon:"fa fa-list-alt",fun:"business_detailsPage"},
				{title:"删除",icon:"fa fa-trash-o",fun:"business_del"},
				{title:"导入",icon:"iconfont icon-shangchuan2",fun:"business_import"},
				{title:"导出",icon:"iconfont icon-xiazai",fun:"business_export"}
			];
		$('.business-list-content').setList(json.list,btnArr,'fa-clipboard');
	}
	function dialog_business_addPage() {
		
			BJUI.dialog({
				id:"businessAddPage",
				url:"/business/editPage",
				title:"添加业务",
				type:"post",
				width:"640",
				height:"600",
				mask:true,
				maxable:false
			})
	} 
	function business_editPage(obj){
		var id=$(obj).parent().parent().prevAll("#item-id").text();
		BJUI.dialog({
			id:"businessEditPage",
			url:"/business/editPage",
			title:"编辑业务",
			type:"post",
			data:{"id":id},
			width:"620",
			height:"600",
			mask:true,
			maxable:false
		})
	}
	function business_detailsPage(obj){
		var id=$(obj).parent().parent().prevAll("#item-id").text();
		BJUI.dialog({
			id:"businessDetails",
			url:"/business/details",
			title:"业务",
			type:"post",
			data:{"id":id},
			width:"620",
			height:"600",
			mask:true,
			maxable:false
		})
		
	}
	function business_del(obj){
		var id=$(obj).parent().parent().prevAll("#item-id").text();
		 BJUI.alertmsg('confirm', '确定要删除吗！', {
	        okCall: function() {
	            BJUI.ajax('doajax', {
				    url: '/business/del',
				    type:"post",
				    data:{"id":id},
				    loadingmask: true,
				    okCallback: function(json, options) {
				    	bussinessTotalNum -=1;
                $('#pagination_business').pagination('destroy')
                $('#pagination_business').pagination({
            total:bussinessTotalNum, pageSize:12, callback:pagination_callback
        });
                       pagination_callback(1,12,1);
                    }
				})
	        }
	    })
		
	}
	function business_import(obj){
		var id=$(obj).parent().parent().prevAll("#item-id").text();
		BJUI.dialog({
	        id:'importData',
	        mask:true,
	        html:'<div class="bjui-pageContent">'+
			        '<form action="/business/importData" method="post"  data-toggle="ajaxform" enctype="multipart/form-data" class="mt-20" data-options="{okCallback:import_callback}" >'+
			        	'<div class="bjui-row col-1">'+
			        		'<label class="row-label">导入模板</label>'+
			        		'<div class="row-input">'+
			        			'<a href="/stuinfo/download" data-toggle="ajaxdownload">导入模板文件下载</a>'+
			        		'</div>'+
			        		'<label class="row-label">上传导入文件</label>'+
			       			'<div class="row-input">'+
			        			'<input type="file" name="file" accept=".xls,.xlsx">'+
			        			'<input type="hidden" name="businessid" value="'+id+'">'+
			        		'</div>'+
			        	'</div>'+
			        '</form>'+
	        	'</div>'+
	        '<div class="btns-group bjui-pageFooter">'+
	        	'<button type="button" class="close-btn" onclick="on_close()">取消</button>'+
	        	'<button type="submit" class="save-btn">保存</button>'+
	        '</div>',
	        title:'导入数据'
	    })
	}
	function on_close(){
		BJUI.dialog('close', 'importData')
	}
	function business_export(obj){
		var id=$(obj).parent().parent().prevAll("#item-id").text();
		var form=$("<form>");//定义一个form表单
		form.attr("style","display:none");
		form.attr("target","");
		form.attr("method","post");
		form.attr("action","/business/exportData");
		var input1=$("<input>");
		input1.attr("type","hidden");
		input1.attr("name","businessid");
		input1.attr("value",id);
		$("body").append(form);//将表单放置在web中
		form.append(input1);
		form.submit();
	}
	function import_callback(json, options){
		if(json.statusCode=='200'){
			BJUI.dialog('close', 'importData');
		}
	}
</script>